package com.fita.admin.entity.search.principal;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

import java.util.Map;

/**
 * 
 * @author cuteHU
 *
 */
public class PrincipalSearch implements QueryBuilder {

    /** 用户名 */
    private String username;

    /** 姓名 */
    private String name;

    /** 电话 */
    private String mobile;

    /** 角色 */
    private String authority;

    /** 关联分区 */
    private Long districtId;

    private QueryFilter queryFilter;

    private QueryOrder queryOrder;

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {
        if (queryFilter == null || refresh) {

            queryFilter = new QueryFilter();

            queryFilter.addLike("username", username)
                       .addLike("name", name)
                       .addLike("mobile", mobile)
                       .addEquals("authority", authority)
                       .addEquals("district.id", districtId);

        }

        return queryFilter;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        if (queryOrder == null) {
            queryOrder = new QueryOrder();
        }
        return queryOrder;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        return "FROM Principal " + getPreparedFilter(false).whereSentence();
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the mobile
     */
    public String getMobile() {
        return mobile;
    }

    /**
     * @return the districtId
     */
    public Long getDistrictId() {
        return districtId;
    }

    /**
     * @return the authority
     */
    public String getAuthority() {
        return authority;
    }

    /**
     * @return the queryFilter
     */
    public QueryFilter getQueryFilter() {
        return queryFilter;
    }

    /**
     * @return the queryOrder
     */
    public QueryOrder getQueryOrder() {
        return queryOrder;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param mobile the mobile to set
     */
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    /**
     * @param authority the authority to set
     */
    public void setAuthority(String authority) {
        this.authority = authority;
    }

    /**
     * @param districtId the districtId to set
     */
    public void setDistrictId(Long districtId) {
        this.districtId = districtId;
    }

    /**
     * @param queryFilter the queryFilter to set
     */
    public void setQueryFilter(QueryFilter queryFilter) {
        this.queryFilter = queryFilter;
    }

    /**
     * @param queryOrder the queryOrder to set
     */
    public void setQueryOrder(QueryOrder queryOrder) {
        this.queryOrder = queryOrder;
    }

}
